package com.zx.mes.hyl.protogenesis;

import io.lettuce.core.RedisClient;
import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.api.sync.RedisCommands;

import java.time.Duration;

/**
 * 原生 redis 连接实现
 * https://lettuce.io/core/release/reference/index.html#basic-usage <br>
 * 如何连接,以及example 示例
 *
 * @author 华云龙
 * @date 2018-12-27
 */
public class RedisTest {

    public static void main(String[] args) {
        RedisClient redisClient = RedisClient.create("redis://10.30.90.136:6379/0");
        /// 过期时间一分钟
        redisClient.setDefaultTimeout(Duration.ofMinutes(1));
        StatefulRedisConnection<String, String> connection = redisClient.connect();
        RedisCommands<String, String> sync = connection.sync();
        sync.set("key", "hello,redis");
        /// 60秒 expire todo expire 还有多少时间如何获取
        sync.setex("expire",60,"60秒自动消失!");
        System.out.println(sync.get("key"));
        System.out.println("expire:"+sync.get("expire"));
        System.out.println();
        connection.close();
        redisClient.shutdown();
    }

}
